/*
 * BinaryOperatorAst.cpp
 *
 *  Created on: 30 Oct 2010
 *      Author: kn308
 */
#include <stdexcept>
#include <MAlice/Parser/location.hh>
#include <sstream>
#include <MAlice/Ast/BinaryOperatorAst.h>

namespace MAlice
{

BinaryOperatorAst::BinaryOperatorAst(location loc, const std::string& operatorName,
		ExpressionAst* lhs, ExpressionAst* rhs) :
	OperatorAst(loc, operatorName), mLHS(lhs), mRHS(rhs)
{
	MALICE_TRACE;

}

BinaryOperatorAst::~BinaryOperatorAst()
{
	MALICE_TRACE;
}

void BinaryOperatorAst::checkType(llvm::Value*& LHS, llvm::Value*& RHS)
{
	MALICE_TRACE;
	if (LHS->getType() != RHS->getType())
	{
		Module* module = Codegen::get()->getModule();

		stringstream ss;
		ss	<< "<" << LHS->getNameStr() << ":" << module->getTypeName(LHS->getType()) << ">LHS" << getOperator() << " "
			<< "<" << RHS->getNameStr() << ":" << module->getTypeName(RHS->getType()) << ">RHS: ";
		ss << "both sides of the equation don't share the same type! Automatic type casting in not implemented yet";
		throw std::runtime_error(ss.str());
	}
}
}
